package karaokestrong.servlets;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import junit.framework.Assert;
import karaokestrong.excepcion.DAOExcepcion;
import karaokestrong.modelo.Local;
import karaokestrong.negocio.GestionLocal;

/**
 * Servlet implementation class ServletLocalActualizar
 */
@WebServlet("/ServletLocalActualizar")
public class ServletLocalActualizar extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletLocalActualizar() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		int localId = Integer.parseInt(request.getParameter("txtId"));
		System.out.println("Actualiza: " + localId);
		
		GestionLocal negocio = new GestionLocal();

		try {
			
		String nombre = request.getParameter("txtNombre");
		String direccion = request.getParameter("txtDireccion");
		int telefono = Integer.parseInt(request.getParameter("txtTelefono"));
		String correo = request.getParameter("txtCorreo");
		String descripcion = request.getParameter("txtDescripcion");
		int idAdmin = Integer.parseInt(request.getParameter("txtAdmin"));
			
			
			  negocio.actualizar(localId, nombre, direccion , telefono, correo, descripcion, idAdmin);
			//request.setAttribute("Local_Actualizado", );
			
			  request.getRequestDispatcher("formlocalactualizar.jsp").forward(request, response);
			/*RequestDispatcher rd = request.getRequestDispatcher("formlocalactualizar.jsp");
			rd.forward(request, response);*/
			
		} catch (DAOExcepcion e) {

			Assert.fail("Fallo el listado: " + e.getMessage());

		}
		
	}

}
